package net.posick.tree;

/**
 * The Tree defines the behavior for a Tree traversal action.
 * 
 * @author Steve Posick
 * 
 * @see Tree
 */
public abstract class TraverseAction<T extends Tree<T, ?>>
{
    /**
     * The action code that tells the Tree traverser to continue with
     * the traversal of the Tree as normal.
     */
    public static final int CONTINUE = 0;
    
    /**
     * The action code that tells the Tree traverser to stop the
     * traversal of the Tree.
     */
    public static final int STOP_TREE = 1;
    
    /**
     * The action code that tells the Tree traverser to stop the
     * traversal of the current branch and move onto the next.
     */
    public static final int STOP_BRANCH = 2;
    
    
    /**
     * Fired for each Tree node during traversal. Allows programmatic
     * control of the traversal as will as providing a simple means to
     * perform some function on the tree's data.
     * 
     * @see Tree
     * @param node
     * @param level
     * @return The Action code.
     */
    public abstract int onNode(T node, int level);
    
    
    /**
     * Fired for each Tree node during traversal, when all of the Tree node's children have been processed.
     * <br>
     * Allows Traverser's that are printing the Tree to close the node after the children have been 
     * processed, such as is the case with XML.
     * 
     * @see Tree
     * @param node
     * @param level
     */
    public void onCloseNode(T node, int level)
    {
    }
}
